import Vue from "vue";
import Router from "vue-router";
import Home from "@/pages/home/Home.vue";
import NotFound from "@/pages/404.vue";
import NProgress from "nprogress";
import "nprogress/nprogress.css";
Vue.use(Router);

// export default new Router({
// 添加路由守卫
const router = new Router({
  routes: [
    {
      path: "/",
      name: "home",
      component: Home
    },
    {
      path: "/city",
      name: "City",
      // 组件按需加载
      component: () => import("@/pages/city/City.vue")
    },
    {
      path: "/user",
      name: "User",
      component: () => import("@/pages/user/User.vue")
    },
    {
      path: "/login",
      name: "Login",
      component: () => import("@/pages/login/Login.vue"),
      children: [
        {
          path: "/login",
          // 重定向
          redirect: "/user/login"
        },
        {
          path: "/user/login",
          name: "login",
          component: () => import("@/pages/login/components/UserLogin.vue")
        },
        {
          path: "/user/register",
          name: "register",
          component: () => import("@/pages/login/components/UserRegister.vue")
        }
      ]
    },
    {
      path: "/agreement",
      name: "Agreement",
      component: () => import("@/pages/agreement/UserAgreement.vue")
    },
    {
      path: "/merchant",
      name: "MerchantList",
      component: () => import("@/pages/merchant/MerchantList.vue"),
      children: [
        {
          path: "/merchant/hotela",
          name: "hotela",
          component: () => import("@/pages/merchant/components/mainPartA.vue")
        },
        {
          path: "/merchant/hotelb",
          name: "hotelb",
          component: () => import("@/pages/merchant/components/mainPartB.vue")
        },
        {
          path: "/merchant/hotelc",
          name: "hotelc",
          component: () => import("@/pages/merchant/components/mainPartC.vue")
        },
        {
          path: "/merchant/hoteld",
          name: "hoteld",
          component: () => import("@/pages/merchant/components/mainPartD.vue")
        }
      ]
    },
    {
      path: "/hotelDetailList/:id",
      name: "HotelDetailList",
      component: () => import("@/pages/hotelDetailList/HotelDetailList.vue")
    },
    {
      path: "/theroomlist",
      name: "TheRoomList",
      component: () => import("@/pages/theroomlist/TheRoomList.vue")
    },
    {
      path: "/roomdetail",
      name: "RoomDetail",
      component: () => import("@/pages/roomDetail/RoomDetail.vue")
    },
    {
      path: "/aboutus",
      name: "AboutUs",
      component: () => import("@/pages/aboutus/AboutUs.vue")
    },
    {
      path: "/MapLocation",
      name: "MapLocation",
      component: () => import("@/pages/public/MapLocation.vue")
    },
    {
      path: "/aaaa",
      name: "aaaa",
      component: () => import("@/pages/user/components/aaaa.vue")
    },
    {
      path: "/order",
      name: "order",
      component: () => import("@/pages/orderManagement/Order.vue")
    },
    {
      path: "*",
      name: "404",
      component: NotFound
    }
  ]
});
// NProgress 路由跳转进度条 开始
router.beforeEach((to, form, next) => {
  // to：将要去到达的路由 form：当前路由 next：做完逻辑必须判断next才会往下走
  NProgress.start();
  next();
});

// 结束
router.afterEach(() => {
  NProgress.done();
});

// 跳转页面不暴露滚动位置
// eslint-disable-next-line no-unused-vars
router.afterEach((to, from, next) => {
  window.scrollTo(0, 0);
});
export default router;
